﻿using System;
using System.Text;

namespace jQueryCSharp.ui
{
    /// <summary>
    /// Classe Fluent para ui.Dialog
    /// </summary>
    public class TabsBuilder : IjQueryCSharpUIBuilder<TabsBuilder>
    {
        private const string Template = "$(\"{0}{1}\").tabs({2});";
        private readonly Tabs _ui;
        private readonly jQueryCSharpUIBuilder _builder;

        /// <summary>
        /// Construtor
        /// </summary>
        /// <param name="builder">jQueryCSharpUIBuilder</param>
        public TabsBuilder( jQueryCSharpUIBuilder builder )
            : this( builder, "" )
        {
        }

        /// <summary>
        /// Construtor
        /// </summary>
        /// <param name="builder">jQueryCSharpUIBuilder</param>
        /// <param name="identifier"></param>
        public TabsBuilder( jQueryCSharpUIBuilder builder, string identifier )
        {
            _ui = new Tabs( identifier );
            _builder = builder;
        }

        #region Métodos

        public TabsBuilder ID( string value )
        {
            _ui.ID = value;
            return this;
        }

        public TabsBuilder Class( string value )
        {
            _ui.Class = value;
            return this;
        }

        public TabsBuilder AddDisabled( int value )
        {
            _ui.Disabled.Add( value );
            return this;
        }

        public TabsBuilder Cache( bool value )
        {
            _ui.Cache = value;
            return this;
        }

        public TabsBuilder Collapsible( bool value )
        {
            _ui.Collapsible = value;
            return this;
        }

        public TabsBuilder Cookie( object value )
        {
            _ui.Cookie = value;
            return this;
        }

        public TabsBuilder Deselectable( bool value )
        {
            _ui.Deselectable = value;
            return this;
        }

        public TabsBuilder TabsDisabled( string value )
        {
            _ui.TabsDisabled = value;
            return this;
        }

        public TabsBuilder Event( string value )
        {
            _ui.Event = value;
            return this;
        }

        public TabsBuilder IdPrefix( string value )
        {
            _ui.IdPrefix = value;
            return this;
        }

        public TabsBuilder PanelTemplate( string value )
        {
            _ui.PanelTemplate = value;
            return this;
        }

        public TabsBuilder Selected( int value )
        {
            _ui.Selected = value;
            return this;
        }

        public TabsBuilder Spinner( string value )
        {
            _ui.Spinner = value;
            return this;
        }

        public TabsBuilder TabTemplate( string value )
        {
            _ui.TabTemplate = value;
            return this;
        }
        #endregion

        #region Override
        public new jQueryCSharpUIBuilder ToString( )
        {
            var sb = new StringBuilder( );

            var sinal = String.IsNullOrEmpty( _ui.Class ) ? "#" : ".";
            var id = String.IsNullOrEmpty( _ui.Class ) ? _ui.ID : _ui.Class;

            sb.AppendFormat( Template, sinal, id, _ui );

            _builder.Append( sb.ToString( ) );

            return _builder;
        }
        #endregion
    }
}
